package apy.codecase.business.view.activity;

import android.content.Intent;
import android.widget.EditText;

import apy.codecase.App;
import apy.codecase.R;
import apy.codecase.base.BaseActivity;
import apy.codecase.business.view.fragment.PswFragment;
import apy.codecase.listener.OnLoadDataListener;
import apy.codecase.model.PswDaoModel;
import apy.codecase.greendao.PswDaoUtils;
import apy.codecase.utils.UIUtils;
import butterknife.BindView;
import butterknife.OnClick;

import static apy.codecase.business.view.fragment.PswFragment.REQUEST_ADD_PSW_TYPE;

/**
 * Created by Administrator on 2017/10/25.
 */

public class AddPswActivity extends BaseActivity{
    @BindView(R.id.add_psw_title)
    EditText addPswTitle;
    @BindView(R.id.add_psw_website)
    EditText addPswWebsite;
    @BindView(R.id.add_psw_account)
    EditText addPswAccount;
    @BindView(R.id.add_psw_psw)
    EditText addPswPsw;

    @Override
    protected String title() {
        return null;
    }

    @Override
    protected boolean controlTitle() {
        return false;
    }

    @Override
    protected int getViewId() {
        return R.layout.activity_add_psw;
    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.add_psw_counfirm)
    public void onViewClicked() {
        String title = UIUtils.getEditText(addPswTitle);
        String website = UIUtils.getEditText(addPswWebsite);
        String account = UIUtils.getEditText(addPswAccount);
        String psw = UIUtils.getEditText(addPswPsw);
        PswDaoUtils userDaoUtils = new PswDaoUtils(this);
        PswDaoModel model = new PswDaoModel();
        model.setAccount(account);
        model.setTitle(title);
        model.setWebsite(website);
        model.setPassword(psw);
        model.setId(App.TICKET);
        boolean state = userDaoUtils.insertUserDaoModel(model);
        if(state){
            Intent intent = new Intent();
            intent.putExtra(REQUEST_ADD_PSW_TYPE,model);
            setResult(PswFragment.REQUEST_ADD_PSW,intent);
            finish();
        }
    }

}
